package com.contory.ssn_lgnd.app.maingame;

import java.util.LinkedList;

import android.util.Log;

import com.contory.ssn_lgnd.app.comp.DrawPtr;
import com.contory.ssn_lgnd.app.comp.UpdatePtr;
import com.contory.ssn_lgnd.framework.gl.SpriteBatcher;

public class EventNotifierManager implements UpdatePtr, DrawPtr{
	LinkedList<EventNotifier> notiList;
	final ColisionManager cm;
	public EventNotifierManager(ColisionManager cm){
		notiList = new LinkedList<EventNotifier>();
		this.cm = cm;
	}
	
	public void addNotifier(float x, float y, float w, float h){
		notiList.add(new EventNotifier(x, y, w, h, cm));
	}
	
	public void addEventGroup(){
		if(notiList.size() == 0){
			try {
				throw new Exception("Fisrt add Notifier");
			} catch (Exception e) {
			  Log.d("ASSERT", e.getMessage());
			}
		}
		notiList.getLast().addEventGroup();
	}
	
	public void addEvent(EventObjectPtr eventObj){
		notiList.getLast().addEvent(eventObj);
	}
	
	@Override
	public void draw(SpriteBatcher batcher) {
		for(int i = 0; i < notiList.size(); i++){
			notiList.get(i).draw(batcher);
		}
	}
	
	@Override
	public void update(float deltaTime) {
		for(int i = 0; i < notiList.size(); i++){
			notiList.get(i).update(deltaTime);
			if(notiList.get(i).getEndBool())
				notiList.remove(notiList.get(i));
		}
	}
}
